package ldh.im.dto.codec.binery;

import io.netty.buffer.ByteBuf;
import ldh.im.dto.codec.BaseImCoder;
import ldh.im.dto.business.TransferFile;

public class TransferFileCoder extends BaseImCoder<TransferFile> {

    @Override
    public void decode(TransferFile transferFile, ByteBuf byteBuf) {
        transferFile.setUserId(byteBuf.readLong());
        transferFile.setMessageId(transferFile.getMessageId());
        transferFile.setMid(readString(byteBuf));
        transferFile.setFileName(readString(byteBuf));
        transferFile.setSize(byteBuf.readLong());
    }

    @Override
    public void encode(TransferFile transferFile, ByteBuf byteBuf) {
        byteBuf.writeLong(transferFile.getUserId());
        writeString(byteBuf, transferFile.getMessageId());
        writeString(byteBuf, transferFile.getMid());
        writeString(byteBuf, transferFile.getFileName());
        byteBuf.writeLong(transferFile.getSize());
    }

    @Override
    public TransferFile create() {
        return new TransferFile();
    }

}
